﻿using System.Runtime.InteropServices;
using OpenGL.Enums;
using OpenGL.Types;

namespace OpenGL
{
    static public partial class GL
    {
        // opengl32.dll 
        [DllImport(OGL_DLL, EntryPoint = "glClearColor")]
        public static extern void ClearColor(float red, float green, float blue, float alpha);
        [DllImport(OGL_DLL, EntryPoint = "glClear")]
        public static extern void Clear(ClearTarget mask);
        [DllImport(OGL_DLL, EntryPoint = "glOrtho")]
        public static extern void Ortho(double left, double right, double bottom, double top, double zNear, double zFar);
        [DllImport(OGL_DLL, EntryPoint = "glBegin")]
        public static extern void Begin(BeginMode mode);
        [DllImport(OGL_DLL, EntryPoint = "glEnd")]
        public static extern void End();
        [DllImport(OGL_DLL, EntryPoint = "glFlush")]
        public static extern void Flush();
        //glu32.dll
        [DllImport(GLU_DLL, EntryPoint = "gluPerspective")]
        public static extern void Perspective(double fovy, double aspect, double zNear, double zFar);

        #region Vertices colors normals
        [DllImport(OGL_DLL, EntryPoint = "glVertex2f")]
        public static extern void Vertex(float x, float y);
        [DllImport(OGL_DLL, EntryPoint = "glVertex2d")]
        public static extern void Vertex(double x, double y);
        [DllImport(OGL_DLL, EntryPoint = "glVertex3d")]
        public static extern void Vertex(double x, double y, double z);
        [DllImport(OGL_DLL, EntryPoint = "glVertex3f")]
        public static extern void Vertex(float x, float y, float z);
        [DllImport(OGL_DLL, EntryPoint = "glNormal3d")]
        public static extern void Normal(double nx, double ny, double nz);
        [DllImport(OGL_DLL, EntryPoint = "glNormal3f")]
        public static extern void Normal(float nx, float ny, float nz);
        [DllImport(OGL_DLL, EntryPoint = "glColor3d")]
        public static extern void Color(double red, double green, double blue);
        [DllImport(OGL_DLL, EntryPoint = "glColor3f")]
        public static extern void Color(float red, float green, float blue);
        [DllImport(OGL_DLL, EntryPoint = "glColor4f")]
        public static extern void Color(float red, float green, float blue, float alpha);
        [DllImport(OGL_DLL, EntryPoint = "glColor4d")]
        public static extern void Color(double red, double green, double blue, double alpha);
        #endregion

        [DllImport(OGL_DLL, EntryPoint = "glEnable")]
        public static extern void Enable(SwitchTarget cap);
        [DllImport(OGL_DLL, EntryPoint = "glEnable")]
        public static extern void Enable(LightName light);
        [DllImport(OGL_DLL, EntryPoint = "glDisable")]
        public static extern void Disable(SwitchTarget cap);
        [DllImport(OGL_DLL, EntryPoint = "glDisable")]
        public static extern void Disable(LightName light);

        [DllImport(OGL_DLL, EntryPoint = "glPolygonOffset")]
        public static extern void PolygonOffset(float a, float b);
        [DllImport(OGL_DLL, EntryPoint = "glLineWidth")]
        public static extern void LineWidth(float width);
        [DllImport(OGL_DLL, EntryPoint = "glBlendFunc")]
        public static extern void BlendFunc(BlendMode sfactor, BlendMode dfactor);
        [DllImport(OGL_DLL, EntryPoint = "glPolygonMode")]
        public static extern void PolygonMode(FaceType face, PolygonMode mode);

        #region Display lists
        [DllImport(OGL_DLL, EntryPoint = "glGenLists")]
        internal static extern DisplayList GenLists(uint count);
        [DllImport(OGL_DLL, EntryPoint = "glNewList")]
        internal static extern void NewList(DisplayList list, ListMode mode);
        [DllImport(OGL_DLL, EntryPoint = "glEndList")]
        internal static extern void EndList();
        [DllImport(OGL_DLL, EntryPoint = "glCallList")]
        internal static extern void CallList(DisplayList list);
        #endregion

        #region Matrix transformations
        [DllImport(OGL_DLL, EntryPoint = "glScaled")]
        public static extern void Scale(double x, double y, double z);
        [DllImport(OGL_DLL, EntryPoint = "glScalef")]
        public static extern void Scale(float x, float y, float z);
        [DllImport(OGL_DLL, EntryPoint = "glRotated")]
        public static extern void Rotate(double angle, double x, double y, double z);
        [DllImport(OGL_DLL, EntryPoint = "glRotatef")]
        public static extern void Rotate(float angle, float x, float y, float z);
        [DllImport(OGL_DLL, EntryPoint = "glTranslated")]
        public static extern void Translate(double x, double y, double z);
        [DllImport(OGL_DLL, EntryPoint = "glTranslatef")]
        public static extern void Translate(float x, float y, float z);
        [DllImport(OGL_DLL, EntryPoint = "glViewport")]
        public static extern void Viewport(int x, int y, int width, int height);
        [DllImport(OGL_DLL, EntryPoint = "glLoadIdentity")]
        public static extern void LoadIdentity();
        [DllImport(OGL_DLL, EntryPoint = "glMatrixMode")]
        public static extern void MatrixMode(MatrixMode mode);
        #endregion

        [DllImport(OGL_DLL)]
        public static extern void glLightModeli(uint pname, int param);        
        [DllImport(OGL_DLL, EntryPoint = "glLightfv")]
        public static extern void Light(LightName light, LightParameter pname, float[] param);
        [DllImport(OGL_DLL, EntryPoint = "glMaterialfv")]
        public static extern void Material(FaceType face, MaterialParameter pname, float[] param);
        [DllImport(OGL_DLL, EntryPoint = "glMaterialf")]
        public static extern void Material(FaceType face, MaterialParameter pname, float param);
        [DllImport(OGL_DLL)]
        public static extern void glColorMaterial(FaceType face, uint mode);
    }
}
